<?php if($this->errMsg) :?>
	<?php $this->showError($this->errMsg)?>
<?php endif; ?>
<?php if($this->msg) :?>		
	<?php $this->showMessage($this->msg)?>	
<?php endif;?>
<?php
$button = "";
if($this->news->status != 1)
	$button = "<a style='text-decoration: none;border-style: solid;' href='javascript:show(".$this->news->id.")' class='btn-32 up'>Đăng tin</a>";
else 
	$button = "<a style='text-decoration: none;border-style: solid;' href='javascript:hide(".$this->news->id.")' class='btn-32 down'>Ẩn tin</a>";
?>
<form name='form' id='form' action="" method="POST">
	<fieldset>
		<legend>
			<div class="title_ad">
				<label style="color: blue;">Nội dung &nbsp;&nbsp;</label>
			</div>
		</legend>
		<label class="Title"><?php echo $this->news->headLines?></label><br>
		<label>
			<?php echo $this->news->content?>
		</label>
	</fieldset>
	<div style="height: 10px"></div>
	<div class="div_button" >	
		<label id='status'><?php echo $button; ?>&nbsp;</label>
		<a style="text-decoration: none;border-style: solid;" href="<?php echo $this->baseUrl().'/admin/news/edit/id/'.$this->news->id;?>" class="btn-32 edit">sửa</a> &nbsp;
		<a style="text-decoration: none;border-style: solid;" href="javascript:del(<?php echo $this->news->id?>)" class="btn-32 delete">xóa tin</a>
	</div>
</form>

<script>
function hide(key){
	if(!confirm("bạn muốn ẩn bài này không??"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/news/active'?> ",
		data: "id=" + key +"&active=0",	
		success: function(msg){
			if(msg == "1")
				$('#status').html("<a style='text-decoration: none;border-style: solid;' href='javascript:show("+key+")' class='btn-32 up'>Đăng tin</a>");
			else
				alert('Error');
		}
	});
}

function show(key){
	if(!confirm("bạn muốn đăng bài này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/news/active'?> ",
		data: "id=" + key +"&active=1",	
		success: function(msg){
			if(msg == "1")	
				$('#status').html("<a style='text-decoration: none;border-style: solid;' href='javascript:hide("+key+")' class='btn-32 down'>Ẩn tin</a>");
			else
				alert('Error');
		}
	});
}
function del(key){
	if(!confirm("Xóa bài đăng này, bạn sẽ xóa các bình luận có liên quan, Bạn có muốn xóa không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/news/delete'?> ",
		data: "id=" + key,	
		success: function(msg){
			if(msg == '1')
				location.replace("<?php echo $this->baseUrl.'/admin/news/index'?>");
			else
				alert('Error');
		}
	});
} 
</script>